import { onUnmounted, ref } from 'vue'


export default function(){
  const isHeng = ref(false)
  const isAnimation = ref(false)

  function setRem (){
    const docEl = document.documentElement
    let { width } = docEl.getBoundingClientRect()
    //let rem = width / 4.14
    if(width > 700){
      width = 700
    }
    let rem = width / 7.5
    if (isHeng.value) {
      rem = width / 13.86
    }
    docEl.style.fontSize = `${rem.toFixed(1)}px`
  }

  /**
   * @description 根据屏幕方向设置显示参数 1.
   * @param args
   */
  function setViewMode () {
    isAnimation.value = true
    if (Math.abs(Number(window.orientation)) === 90) {
      isHeng.value = true
    } else {
      isHeng.value = false
    }

    setTimeout(() => {
      setRem()
      isAnimation.value = false
    }, 100)
  }

  setViewMode()

  window.addEventListener('orientationchange', setViewMode)

  onUnmounted(() => {
    window.removeEventListener('orientationchange', setViewMode)
  })

  return {
    isHeng,
    isAnimation
  }
}
